package com.xiaoyi.enums;


import com.xiaoyi.encrypt.*;

/**
 * @author xiaoyi
 * @version 1.0.0
 * @date 2023/08/01 15:05:00
 */
public enum AlgorithmEnum {

    DEFAULT("DEFAULT", DefaultEncryptor.class),
    AES("AES", AesEncryptor.class),
    Md532("Md532", Md532Encryptor.class),
    Md516("Md516", Md516Encryptor.class),
    BASE64("BASE64", Base64Encryptor.class),
    RSA("RSA", RsaEncryptor.class),
    SM2("SM2",Sm2Encryptor.class),
    SM3("SM3", Sm3Encryptor.class),
    SM4("SM4", Sm4Encryptor.class);
    private Class value;
    private String key;

    private AlgorithmEnum(String key, Class value) {
        this.value = value;
        this.key = key;
    }

    public Class getValue() {
        return value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setValue(Class value) {
        this.value = value;
    }

    public static Class getValueBykey(String key) {
        AlgorithmEnum[] algorithmEnums = values();
        for (AlgorithmEnum itemEnum : algorithmEnums) {
            if (itemEnum.key.equals(key)) {
                return itemEnum.getValue();
            }
        }
        return null;
    }
    public static String getKeyByValue(Class value) {
        for (AlgorithmEnum itemEnum : AlgorithmEnum.values()) {
            if (value.equals(itemEnum.getValue())) {
                return itemEnum.getKey();
            }
        }
        return null;
    }
    public static AlgorithmEnum getAlgorithmEnumBykey(String key) {
        AlgorithmEnum[] algorithmEnums = values();
        for (AlgorithmEnum itemEnum : algorithmEnums) {
            if (itemEnum.key.equals(key)) {
                return itemEnum;
            }
        }
        return null;
    }


}
